package org.nstack.header.storage.primary;

import org.springframework.http.HttpMethod;
import org.nstack.header.cluster.ClusterVO;
import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.RestRequest;


@RestRequest(
        path = "/clusters/{clusterUuid}/primary-storage/{primaryStorageUuid}",
        method = HttpMethod.POST,
        responseClass = APIAttachPrimaryStorageToClusterEvent.class
)
public class APIAttachPrimaryStorageToClusterMsg extends APIMessage implements PrimaryStorageMessage {

    @APIParam(resourceType = ClusterVO.class)
    private String clusterUuid;

    @APIParam(resourceType = PrimaryStorageVO.class)
    private String primaryStorageUuid;

    public APIAttachPrimaryStorageToClusterMsg() {
    }

    public APIAttachPrimaryStorageToClusterMsg(String clusterUuid, String uuid) {
        super();
        this.clusterUuid = clusterUuid;
        this.primaryStorageUuid = uuid;
    }

    public String getClusterUuid() {
        return clusterUuid;
    }

    public void setClusterUuid(String clusterUuid) {
        this.clusterUuid = clusterUuid;
    }

    @Override
    public String getPrimaryStorageUuid() {
        return primaryStorageUuid;
    }

    public void setPrimaryStorageUuid(String primaryStorageUuid) {
        this.primaryStorageUuid = primaryStorageUuid;
    }

 
    public static APIAttachPrimaryStorageToClusterMsg __example__() {
        APIAttachPrimaryStorageToClusterMsg msg = new APIAttachPrimaryStorageToClusterMsg();

        msg.setPrimaryStorageUuid(uuid());
        msg.setClusterUuid(uuid());

        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                if (evt.isSuccess()) {
                    ntfy("Attached to cluster[uuid:%s]", clusterUuid).resource(primaryStorageUuid, PrimaryStorageVO.class.getSimpleName())
                            .context("clusterUuid", clusterUuid)
                            .messageAndEvent(that, evt).done();

                    ntfy("Attached to primary storage[uuid:%s]", primaryStorageUuid).resource(clusterUuid, ClusterVO.class.getSimpleName())
                            .context("primaryStorageUuid", primaryStorageUuid)
                            .messageAndEvent(that, evt).done();
                }
            }
        };
    }
}
